home *** CD-ROM | disk | FTP | other *** search
- property pLastFrameTime, pCheckMovementTimeout, pFrameTimes, pFinishedTime, pBeginTime
- global gCamera, gCar, gWorld, gRacers, gHaveSound, gSparkLocs, gSparkCount, gSparkSystems, gCollDetails, gLastTrackCollision, gLastCarCollision, gFinished, gFrameRate, gTimeStep, gHavok, gLastCollSound, gCurrentVel
-
- on beginSprite me
- pLastFrameTime = the milliSeconds
- pFrameTimes = []
- repeat with i = 1 to 30
- add(pFrameTimes, the milliSeconds)
- end repeat
- pBeginTime = the milliSeconds
- gCar = gWorld.model("carModel_1")
- end
-
- on exitFrame
- checkForExit()
- checkForMovement()
- if gHaveSound then
- if not sound(1).isBusy() then
- sound(1).play(member("cracermusic"))
- end if
- end if
- add(pFrameTimes, the milliSeconds)
- deleteAt(pFrameTimes, 1)
- timePerFrame = (pFrameTimes[pFrameTimes.count] - pFrameTimes[1]) / float(pFrameTimes.count)
- if timePerFrame < 10 then
- timePerFrame = 10
- else
- if timePerFrame > 100 then
- timePerFrame = 100
- end if
- end if
- gTimeStep = timePerFrame / 1000.0
- gFrameRate = 1000.0 / timePerFrame
- if gRacers[1].pCourseTime then
- if pFinishedTime then
- if (the milliSeconds - pFinishedTime) > 1500 then
- the timeOutList = []
- go("Course Screen")
- else
- go(the frame)
- end if
- else
- if gCurrentVel.magnitude < 50 then
- pFinishedTime = the milliSeconds
- end if
- go(the frame)
- end if
- else
- if gFinished then
- the timeOutList = []
- stopSounds()
- gCurrTrack = gCurrTrack - 1
- go("Tweak Car")
- else
- go(the frame)
- end if
- end if
- end
-
- on prepareFrame me
- timeElapsed = the milliSeconds - pLastFrameTime
- currTime = the milliSeconds
- repeat with i = 1 to gRacers.count
- gRacers[i].updateCarFloat()
- end repeat
- updateCamera()
- updateSpeedometer()
- checkCollisions()
- checkPowerups()
- updateSky()
- pLastFrameTime = the milliSeconds
- end
-
- on playCollisionSound theSound, theLoc
- if gHaveSound then
- gLastCollSound = gLastCollSound + 1
- if gLastCollSound > 4 then
- gLastCollSound = 3
- end if
- tempVec = gCar.worldPosition - theLoc
- tempVec.normalize()
- rightDot = gRacers[1].pWorldRight.dot(tempVec)
- myPan = 100 * rightDot
- sound(gLastCollSound).stop()
- sound(gLastCollSound).setPlayList([[#member: member(theSound)]])
- sound(gLastCollSound).play()
- sound(gLastCollSound).volume = 140
- sound(gLastCollSound).pan = myPan
- end if
- end
-
- on getTimePassed me
- return the milliSeconds - pBeginTime
- end
-
- on checkCollisions
- if gCollDetails.count > 0 then
- repeat with i = 1 to gCollDetails.count
- if gCollDetails[i][2] contains "track" then
- if gCurrentVel.magnitude > 50 then
- if (the milliSeconds - gLastTrackCollision) > 1000 then
- playCollisionSound("scrape", gCollDetails[i][3])
- gLastTrackCollision = the milliSeconds
- end if
- end if
- next repeat
- end if
- if (the milliSeconds - gLastCarCollision) > 300 then
- playCollisionSound("impactshrt", gCollDetails[i][3])
- gLastCarCollision = the milliSeconds
- end if
- end repeat
- gCollDetails = []
- end if
- repeat with i = gSparkLocs.count down to 1
- theLoc = gSparkLocs[i]
- theSin = sin(-gRacers[1].pTurnData.currentTurn / 180 * PI)
- theCos = cos(-gRacers[1].pTurnData.currentTurn / 180 * PI)
- theNewLoc = vector(0, 0, 0)
- theNewLoc.x = (theCos * theLoc.x) + (theSin * theLoc.z)
- theNewLoc.z = (theSin * theLoc.x) + (theCos * theLoc.z)
- gSparkCount = gSparkCount + 1
- ts = gWorld.newModelResource("SparkSystem_" & gSparkCount, #particle)
- ts.sizeRange.start = 0.10000000000000001
- ts.sizeRange.end = 0.20000000000000001
- ts.lifeTime = 750
- ts.emitter.minSpeed = 60
- ts.emitter.maxSpeed = 80
- ts.colorRange.end = rgb("FF9900")
- ts.colorRange.start = rgb("FFFF00")
- ts.emitter.angle = 5
- ts.emitter.direction = vector(0, 0, 1)
- ts.emitter.numParticles = 7
- ts.emitter.mode = #burst
- ts.emitter.loop = 0
- tm = gWorld.newModel("SparkModel_" & gSparkCount, ts)
- tm.transform.position = theNewLoc
- tm.parent = gCar.parent
- add(gSparkSystems, tm)
- deleteAt(gSparkLocs, i)
- end repeat
- if gSparkSystems.count > 20 then
- repeat with i = gSparkSystems.count - 20 down to 1
- gWorld.deleteModelResource(gSparkSystems[i].resource.name)
- gWorld.deleteModel(gSparkSystems[i].name)
- deleteAt(gSparkSystems, i)
- end repeat
- end if
- end
-